package com.tkjt.pms.modules.gm.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tkjt.pms.modules.common.service.TkDataConfigService;
import com.tkjt.pms.modules.gm.vo.CommentsVo;
import com.tkjt.pms.modules.gm.vo.TkGmScoresVo;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tkjt.pms.common.entity.TkDataConfig;
import com.tkjt.pms.common.utils.EsStringUtils;
import com.tkjt.pms.common.vos.TkIndexValueForScoreVO;
import com.tkjt.pms.modules.common.mapper.TkDataConfigMapper;
import com.tkjt.pms.modules.gm.service.TkGmBizService;
import com.tkjt.pms.modules.gm.service.TkGmService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
@Transactional
public class TkGmServiceImpl implements TkGmService {

	@Autowired
	private TkDataConfigService tkDataConfigService;

	@Autowired
	private Map<String, TkGmBizService> tkGmServiceMap = new HashMap<>();

	@Override
	public Map<String, Object> gmGradedRadio(LoginUser loginUser, String yearMonth) {
		String dataType = tkDataConfigService.getDataType(loginUser.getUsername());

		log.info("indexYearMonth={},dataType={}", yearMonth, dataType);

		TkGmBizService tkGmBizService = checkService(dataType);
		return tkGmBizService.gmGradedRadio(loginUser, yearMonth, dataType);
	}

	@Override
	public Result<?> gmDatagrid(LoginUser loginUser, TkIndexValueForScoreVO tkIndexValue, Integer pageNo, Integer pageSize) {
		String dataType = tkDataConfigService.getDataType(loginUser.getUsername());
		TkGmBizService tkGmBizService = checkService(dataType);
		return tkGmBizService.gmDatagrid(tkIndexValue, pageNo, pageSize, loginUser, dataType);
	}

	@Override
	public Map<String, Object> cgDatagrid(LoginUser loginUser, TkIndexValueForScoreVO tkIndexValue, Integer pageNo, Integer pageSize) {
		String dataType = tkDataConfigService.getDataType(loginUser.getUsername());
		TkGmBizService tkGmBizService = checkService(dataType);
		return tkGmBizService.cgDatagrid(loginUser,tkIndexValue, pageNo, pageSize, dataType);
	}

	@Override
	public Map<String, Object> doubleDatagrid(LoginUser loginUser, TkIndexValueForScoreVO tkIndexValue, Integer pageNo, Integer pageSize) {
		String dataType = tkDataConfigService.getDataType(loginUser.getUsername());
		TkGmBizService tkGmBizService = checkService(dataType);
		return tkGmBizService.doubleDatagrid(tkIndexValue, pageNo, pageSize, dataType);
	}


	@Override
	public Result<?> scoreDatagrid(LoginUser loginUser, TkIndexValueForScoreVO tkIndexValue, Integer pageNo, Integer pageSize) {
		String dataType = tkDataConfigService.getDataType(loginUser.getUsername());
		TkGmBizService tkGmBizService = checkService(dataType);
		return tkGmBizService.scoreDatagrid(tkIndexValue, pageNo, pageSize, dataType);
	}

	@Override
	public Result<?> scoreGmDatagrid(LoginUser loginUser, TkIndexValueForScoreVO tkIndexValue) {
		String dataType = tkDataConfigService.getDataType(loginUser.getUsername());
		TkGmBizService tkGmBizService = checkService(dataType);
		return tkGmBizService.scoreGmDatagrid(tkIndexValue, dataType);
	}

	@Override
	public Result<?> saveScores(LoginUser loginUser, String indexYearMonth, List<TkIndexValueForScoreVO> tkIndexValueVOs) {
		String dataType = tkDataConfigService.getDataType(loginUser.getUsername());
		TkGmBizService tkGmBizService = checkService(dataType);
		return tkGmBizService.saveScores(loginUser.getUsername(), indexYearMonth, tkIndexValueVOs, dataType);
	}

	@Override
	public Result<?> getCommentsReport(LoginUser loginUser, CommentsVo commentsVo) {
		String dataType = tkDataConfigService.getDataType(loginUser.getUsername());
		TkGmBizService tkGmBizService = checkService(dataType);
		return tkGmBizService.getCommentsReport(loginUser,commentsVo,dataType);
	}

	public TkGmBizService checkService(String dataType) {
		String serviceName = "tkGmBizService" + EsStringUtils.onlyFirstCharUpper(dataType);
		return tkGmServiceMap.get(serviceName);
	}

}
